<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="商户号" prop="memberId">
        <el-input
          v-model="queryParams.memberId"
          placeholder="请输入商户号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="币种标识" prop="symbol">
        <el-input
          v-model="queryParams.symbol"
          placeholder="请输入标识"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
       <el-form-item label="交易ID" prop="txid">
        <el-input
          v-model="queryParams.txid"
          placeholder="请输入交易ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业务状态" prop="bizStatus">
          <el-select v-model="queryParams.bizStatus" placeholder="业务状态" size="small" :clearable="true">
            <el-option
              v-for="(v, k) in bizStatusMap"
              :key="k"
              :label="v"
              :value="k"
            />
          </el-select>
        </el-form-item>
      <el-form-item label="回调状态" prop="status">
          <el-select v-model="queryParams.status" placeholder="状态" size="small" :clearable="true">
            <el-option
              v-for="(v, k) in statusMap"
              :key="k"
              :label="v"
              :value="k"
            />
          </el-select>
        </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5"></el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="postList">
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="商户号" align="center" prop="memberId" />
      <el-table-column label="币种ID" align="center" prop="coinId" />
      <el-table-column label="币种标识" align="center" prop="coinSymbol" />
      <el-table-column label="金额" align="center" prop="amount" />
      <el-table-column label="到帐地址" align="center" prop="toAddress">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleViewAddress(scope.row.toAddress, '到帐地址')">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column label="交易ID" align="center" prop="txid">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleViewAddress(scope.row.txid, '交易ID')">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column label="业务流水号" align="center" prop="bizNo">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleViewAddress(scope.row.bizNo, '业务流水号')">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column label="业务状态" align="center" prop="bizStatus">
        <template slot-scope="scope">
          {{ bizStatusMap[scope.row.bizStatus] }}
        </template>
      </el-table-column>
      <el-table-column label="回调次数" align="center" prop="notifyCount" />
      <el-table-column label="回调状态" align="center" prop="status">
        <template slot-scope="scope">
          {{ statusMap[scope.row.status] }}
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleViewAddress(scope.row.remark, '备注')">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="ctime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.ctime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改时间" align="center" prop="ctime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.mtime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.limit"
      @pagination="getList"
    />

    <el-dialog :title="dialogAddress.title" :visible.sync="dialogAddress.visible" width="30%">
      <span>{{ dialogAddress.value }}</span>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogAddress.visible = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>

import { listMemberNotify  } from "@/api/aipay/memberNotify";

export default {
  name: "Notify",
  dicts: ['sys_bool_status'],
  data() {
    return {
      dialogAddress: {
        visible: false,
        title: '',
        value: ''
      },
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //表格数据
      postList: [],
      roleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      activeName: "public",
      // 查询参数
      queryParams: {
        page: 1,
        limit: 10
      },
      // 表单参数
      form: {
      },
      // 表单校验
      rules: {},
      bizStatusMap: {
        0: '成功',
        1: '失败'
      },
      statusMap: {
        0: '未触发',
        1: '已触发',
        2: '异常'
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      listMemberNotify(this.queryParams).then(response => {
        this.postList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.postId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    handleViewAddress(value, title){
      this.dialogAddress.title = title
      this.dialogAddress.value = value
      this.dialogAddress.visible = true
    },
  }
};
</script>
